package com.littleken.foodiePojo.enums;

/*
 * Create by littleken on 2020/11/24 14:34
 */
public enum CommentLevelEnum {
    GOOD(1, "好评"),
    NORMAL(2, "中评"),
    BAD(3, "差评");

    private Integer code;
    private String desc;

    CommentLevelEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
    /**
     * 通过 CODE 获取 DESC
     * @param code
     * @return
     */
    public static String getDescByCode(Integer code) {
        for (CommentLevelEnum commentLevel :CommentLevelEnum.values()) {
            if (commentLevel.code.equals(code)) {
                return commentLevel.desc;
            }
        }
        return null;
    }

    /**
     * 通过 DESC 获取 CODE
     * @param desc
     * @return
     */
    public static Integer getCodeByDesc(String desc) {
        for (CommentLevelEnum commentLevel : CommentLevelEnum.values()) {
            if (commentLevel.desc.equals(desc)) {
                return commentLevel.code;
            }
        }
        return null;
    }

    /**
     * 通过 CODE 获取 Enum
     * @param code
     * @return
     */
    public static CommentLevelEnum getEnumByCode(Integer code) {
        for (CommentLevelEnum CommentLevel :CommentLevelEnum.values()) {
            if (CommentLevel.code.equals(code)) {
                return CommentLevel;
            }
        }
        return null;
    }
}
